package com.link2room.jetfire.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.jetfire.facade.IReservationFacadeService;
import com.link2room.jetfire.dto.param.base.ReservationParamDto;
import com.link2room.jetfire.dto.param.inside.ReservationBaseInsideParamDto;
import com.link2room.jetfire.dto.param.inside.ReservationNmsStaInsideParamDto;
import com.link2room.jetfire.dto.param.inside.ReservationPayInsideParamDto;
import com.link2room.jetfire.dto.result.base.ReservationBaseDto;
import com.link2room.jetfire.dto.result.base.ReservationDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by sss on 2016/9/20.
 */
@Api(tags = "订单相关")
@RestController
@RequestMapping("/in/Reservations")
public class ReservationInsideController {
    @Resource
    private IReservationFacadeService reservationFacadeService;

    @ApiOperation(value = "新建订单",response = ReservationBaseDto.class)
    @RequestMapping(method= RequestMethod.POST)
    public BaseResultDto createReservation(@RequestBody ReservationParamDto reservationParamDto) throws Exception {
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(reservationFacadeService.createReservation(reservationParamDto));
        return l2rRs;
    }

    @ApiOperation(value = "更新订单确认状态")
    @RequestMapping(value = "/ConfirmSta",method= RequestMethod.PUT)
    public BaseResultDto confirmSta(@RequestBody ReservationNmsStaInsideParamDto reservationNmsStaInsideParamDto) throws Exception {
        reservationFacadeService.updateReservationNmsSta(reservationNmsStaInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "订单入账")
    @RequestMapping(value = "/Payments",method= RequestMethod.POST)
    public BaseResultDto payment(@RequestBody ReservationPayInsideParamDto reservationPayInsideParamDto) throws Exception {
        reservationFacadeService.saveReservationPay(reservationPayInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "更新订单状态")
    @RequestMapping(value = "/ResSta",method= RequestMethod.PUT)
    public BaseResultDto resSta(@RequestBody ReservationBaseInsideParamDto reservationBaseInsideParamDto) throws Exception {
        reservationFacadeService.updateReservationBase(reservationBaseInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "取消订单")
    @RequestMapping(method = RequestMethod.DELETE)
    public BaseResultDto cancelReservation(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "l2rNo" ,required = false) String l2rNo,
            @RequestParam(value = "terminalNo" ,required = false) String terminalNo
    )throws Exception{
        ReservationParamDto reservationParamDto=new ReservationParamDto();
        reservationParamDto.setLhotelCode(lhotelCode);
        reservationParamDto.setL2rNo(l2rNo);
        reservationParamDto.setTerminalNo(terminalNo);
        reservationParamDto.setNow(new Date());
        reservationFacadeService.cancelReservationBase(reservationParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "按条件获取订单详情",response = ReservationDto.class)
    @RequestMapping(value = "/Reservation",method = RequestMethod.GET)
    public BaseResultDto getReservation(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "l2rNo" ,required = false) String l2rNo,
            @RequestParam(value = "terminalNo" ,required = false) String terminalNo,
            @RequestParam(value = "confirmSta" ,required = false) String confirmSta,
            @RequestParam(value = "resSta" ,required = false) String resSta
    )throws Exception{
        ReservationParamDto reservationParamDto=new ReservationParamDto();
        reservationParamDto.setLhotelCode(lhotelCode);
        reservationParamDto.setL2rNo(l2rNo);
        reservationParamDto.setTerminalNo(terminalNo);
        reservationParamDto.setConfirmSta(confirmSta);
        reservationParamDto.setResSta(resSta);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(reservationFacadeService.findReservation(reservationParamDto));
        return l2rRs;
    }

    @ApiOperation(value = "退款状态更新")
    @RequestMapping(value = "/RefundSta",method= RequestMethod.PUT)
    public BaseResultDto updateRefundSta(@RequestBody ReservationPayInsideParamDto reservationPayInsideParamDto) throws Exception {
        reservationFacadeService.updateReservationAccountRefundSta(reservationPayInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
